<?php

namespace App\Http\Resources;

use App\Models\Category;
use Illuminate\Http\Resources\Json\JsonResource;

class BookmarkResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    public function toArray($request)
    {
        // $user = \App\Models\User::find($this->user_id); // 直接用 User 模型
        // $category = Category::find($this->category_id); // 直接用 Category 模型

        return [
            'id' => $this->id,
            'user' => new UserSimpleResource($this->user), // 使用模型关联关系，调用 user
            'title' => $this->title,
            'url' => $this->url,
            'category_id' => new CategoryResource($this->category), // 使用模型关联关系，调用 category
            'summary' => $this->summary,
            'status' => $this->status,
            'created_at' => $this->created_at,
            'updated_at' => $this->updated_at
        ];
    }
}
